package physics;

import java.awt.event.ActionEvent;

import physics.Collisions.Collision;
import physics.MovementControl.JumperMovementController;
import viewControllers.ViewControllersFactory;

import common.Math3D;

public class Grenade extends Weapon {

	double jumpStrength = 0.3;
	private int ticksToExplosion = 50;
	
	
	public Grenade(){
		ticksToDisappear = 20;
		this.setMovementControler(new JumperMovementController(this));
		this.getMovementControler().setMovementLimit(0.5);
	}
	
	
	
	public void impact(Collision c){
		GameObject bumpedInto;	
		if (c.getObj1().equals(this))
			bumpedInto= c.getObj2();
		else
			bumpedInto = c.getObj1();

		switch (c.getType()){
			case GRENADE:
				
				break;
			case DEFAULT:
//				getMovementControler().restoreLastPosition();
//				getMovementControler().setHasMomentum(false);
//				this.setGraphicalObject(ViewControllersFactory.createExplosionViewController(this)); 
//				dying = true;
				break;
		}
	}
	
	
	public void clockTicked(ActionEvent arg0) {
		
		super.clockTicked(arg0);
		if (!exploded){
			if (ticks++ >= ticksToExplosion ){
				explode();
			}
		}
	}
	
	
	

	public void jump(){
		jump(jumpStrength);
	}
	
	private void jump(double strength){
		this.getMovementControler().addMovement(
				Math3D.scalePoint(getUp(), strength));
		this.getMovementControler().addMovement(
				Math3D.scalePoint(getFace(), strength));
	}

}
